//最大子段和
https://www.luogu.com.cn/problem/P1115#ide

#include <iostream>
using namespace std;

typedef long long LL;
const int N = 2e5 + 10;
int a[N];

int main()
{
    int n;
    cin >> n;

    LL sum = 0;
    LL ret = -1e6;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

    int left = 1,right = 1;
    while (right <= n)
    {
        //入窗口
        sum += a[right];
        //判断窗口是否合法
        if (sum <= 0)
        { //不合法
            ret = max(ret, sum);
            left = right;
            sum = 0;   
        }
        else
        {
            //合法
            ret = max(ret, sum);
        }
        right++;
    }

    cout << ret;
    return 0;
}